using System;
using System.Collections.Generic;
using UnityEngine;

public class PoolManager : SingletonManager<PoolManager>
{
    //此为不频繁创建物体
    public GameObject swordObj;//终剑
    //死亡墓碑
    public GameObject playerDieObj;
    //伤害特效
    public Material hurtMat;
    [Header("伤害数字")]
    public Pool damageNum;
    [Header("回血数字")]
    public Pool addHpNum;
    [Header("其他提示")]
    public Pool otherText;
    [Header("普通死亡特效")]
    public Pool normalDieEffect;
    [Header("门上下特效")]
    public Pool doorEffectUd;
    [Header("门左右特效")]
    public Pool doorEffectLr;

    //获取伤害数字
    public GameObject GetDamageNum()
    {
        Pool pool = damageNum;
        for(int i=0;i<pool.list.Count;i++)
        {
            if (pool.list[i].activeSelf==false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
    //获取回血数字
    public GameObject GetAddHpNum()
    {
        Pool pool = addHpNum;
        for (int i = 0; i<pool.list.Count; i++)
        {
            if (pool.list[i].activeSelf==false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
    //获取其他文本
    public GameObject GetOtherText()
    {
        Pool pool = otherText;
        for (int i = 0; i<pool.list.Count; i++)
        {
            if (pool.list[i].activeSelf==false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
    //获取死亡特效
    public GameObject GetNormalDieEffect()
    {
        Pool pool = normalDieEffect;
        for (int i = 0; i < pool.list.Count; i++)
        {
            if (pool.list[i].activeSelf == false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
    //获取门上下特效
    public GameObject GetDoorEffectUd()
    {
        Pool pool = doorEffectUd;
        for (int i = 0; i < pool.list.Count; i++)
        {
            if (pool.list[i].activeSelf == false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
    //获取门左右特效
    public GameObject GetDoorEffectLr()
    {
        Pool pool = doorEffectLr;
        for (int i = 0; i < pool.list.Count; i++)
        {
            if (pool.list[i].activeSelf == false)
            {
                pool.list[i].SetActive(true);
                return pool.list[i];
            }
        }
        //实例化
        GameObject obj = Instantiate(pool.obj);
        obj.transform.SetParent(transform);
        pool.list.Add(obj);
        return obj;
    }
}

[Serializable]
public class Pool
{
    [Header("物品")]
    public GameObject obj;
    public List<GameObject> list = new List<GameObject>();
}